//index.js
//获取应用实例
const app = getApp()
const baseUrl = app.picimg;
const url = "bgPic.png";
const wb_bg_url ="white_bg.png";
var imgurl = "";
var imgurl2="";
var hours;
var minutes;
var seconds;
var time_djs;
var time_key;
Page({
  data: {
    motto: '明早打卡可随机瓜分金额（元）',
    score: '我的战绩',
    totle: "190,183",
    money:152632,
    wdzj:"我的战绩",
    shareData: {
      title: '早起打卡',
      desc: '早起打卡2',
      path: '/pages/index/index'
    }
   
  },
  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    var that = this;
    // var date=new Date();
    
    var time_now ="1529654515";
    var time_end = "1529654530";
     time_djs=time_end-time_now;
    // var time_djs=0;
     console.log(time_djs);

     if(time_djs==0){
       hours=0;minutes=0;seconds=0;
       that.setData({
         time_key: true
       })
     }else{
      hours = parseInt(time_djs / 3600);
       minutes = parseInt(((time_djs / 3600) - hours) * 60);
       seconds = time_djs % 60;
       if (minutes < 10 && minutes > 0) {
         minutes = "0" + minutes;
       }
       if (minutes == 0) {
         minutes = "00";
       }
       if (seconds < 10) {
         seconds = "0" + seconds;
       }
       if (seconds == 0) {
         seconds = "00";
       }
     }
    that.setData({
      imgurl: baseUrl.url + url,
      time_key:false,
      looks:true,
     
    });

  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
 
  onReady:function(){
    var that=this;
   
    var interval = setInterval(function () { 
      hours = parseInt(time_djs / 3600);
      minutes = parseInt(((time_djs / 3600) - hours) * 60);
      seconds = time_djs % 60;
      if (minutes < 10 && minutes > 0) {
        minutes = "0" + minutes;
      }
      if (minutes == 0) {
        minutes = "00";
      }
      if (seconds < 10) {
        seconds = "0" + seconds;
      }
      if (seconds == 0) {
        seconds = "00";
      }
      that.setData({
        time_key: false,
        hours: hours,
        minutes: minutes,
        seconds: seconds
      });
      time_djs--;
        if(time_djs<0){
          clearInterval(interval);
          that.setData({
            time_key: true,
            hours: "00",
            minutes: "00",
            seconds: "00"
          });
        }
     },1000)
  },

   clock_in: function (e) {
    var that = this;
    that.setData({
      time_djs: 0,
      looks:false,
      imgurl2: baseUrl.url + wb_bg_url,
    })
   
  },
   isgrey:function(e){
     this.setData({
       looks:true,
     });
   },

   //防止点击穿透 背景层
   preventD: function () {

   },
   clickme:function(e){
     this.setData({
       looks: false
     });
   },
   tiaozhuan:function(){
     wx:wx.navigateTo({
       url: '../index/index',
       success: function(res) {
         console.log("success");
       },
       fail: function(res) {},
       complete: function(res) {},
     })
   },
   onShareAppMessage:function(){
     return this.data.shareData
   },
   onshare: function () {
     wx.showShareMenu({
       withShareTicket: true,
       success: function (res) {
         console.log("ok");


       },
       fail: function (res) { },
       complete: function (res) { },
     })
   },
   myscore:function(){
     wx.navigateTo({
       url: '../myscore/myscore',
     })
   },
   tzgz:function(){
     wx:wx.navigateTo({
       url: '../tzgz/tzgz',
       success: function(res) {},
       fail: function(res) {},
       complete: function(res) {},
     })
   }
})
